获取阿里云STS凭证报错SDK.ServerUnreachable

目录
  1. 问题
  2. 解决

问题

最近做捣鼓Web端OSS直传,比较安全的直传方式有两种,使用后端签名直传 和 使用STS凭证直传, OSS官方Web端直传例子中使用的是后端签名直传,移动端直传例子使用的STS凭证,相关SDK例子使用的是STS凭证。项目前端使用的是react + antd,因此打算参考使用STS凭证 + ali-oss 进行直传,以后也能复用在移动端上传。

完成相关代码后获取凭证报错。
获取阿里云STS凭证失败

1
2
3
4
5
org.apache.http.impl.execchain.RetryExec - I/O exception (org.apache.http.conn.UnsupportedSchemeException) caught when processing request to {s}->https://sts.aliyuncs.com:443: https protocol is not supported

org.apache.http.impl.execchain.RetryExec - Retrying request to {s}->https://sts.aliyuncs.com:443

me.gelu.base.framework.aliyun.oss.OSSService - {StatusCode=500, ErrorCode=SDK.ServerUnreachable, ErrorMessage=Server unreachable: org.apache.http.conn.UnsupportedSchemeException: https protocol is not supported}

解决

参考文档,对比POM文件,发现core依赖版本可能过高,最近正好升级过依赖版本。

阿里云STS POM版本配置

当前依赖版本

1
2
3
4
5
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.0.2</version>
</dependency>

降级为截图中的3.5.0即可。

1
2
3
4
5
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>3.5.0</version>
</dependency>

这应该不是唯一能用的版本,尝试降到3.7.1,依旧报错,降到升级前版本3.2.8则新编写的STS凭证代码无法使用,需要改写。因此直接参考截图进行配置,获取凭证成功。

阿里云STS凭证获取成功